/*
 * GroupService.java
 *
 * Copyright 2012 the original author or authors(ninglong).
 *
 * Licensed under the org.geek.group.service, Version 1.0 (the "License");
 *
 */
package org.geek.group.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.geek.common.entity.Criteria;
import org.geek.common.entity.Menu;
import org.geek.domain.Group;
import org.geek.group.mapper.GroupMapper;
import org.geek.group.service.IGroupService;
import org.springframework.stereotype.Service;

/**
 * <p></p>
 * @author ninglong bhd2973@qq.com
 * @version V1.0
 */
@Service
public class GroupService implements IGroupService {

	@Resource
	private GroupMapper groupMapper;

	public List<Menu> getGroups2Menu(int userId) {
		Criteria criteria = new Criteria();
		List<Group> list = null;
		if(userId==0){
			list = groupMapper.getGroupByCriteria(criteria);
		}else{
			list = groupMapper.getGroup2User(userId);
		}
		List<Menu> menus = new ArrayList<Menu>();
		for(Group group : list){
			Menu menu = new Menu();
			menu.setId(group.getGroupId());
			menu.setName(group.getGroupName());
			menu.setParentId(group.getParentId());
			menus.add(menu);
		}
		return menus;
	}

	public int countGroupByCriteria(Criteria criteria) {
		return groupMapper.countGroupByCriteria(criteria);
	}

	public List<Group> getGroupByCriteria(Criteria criteria) {
		return groupMapper.getGroupByCriteria(criteria);
	}

	public int modGroup(Group group) {
		return groupMapper.modGroup(group);
	}

	public int addGroup(Group group) {
		return groupMapper.addGroup(group);
	}

	public int delGroupByGroupId(int groupId) {
		return groupMapper.delGroupByGroupId(groupId);
	}
}